package com.gitee.huanminabc.validate;


import com.gitee.huanminabc.jcommon.model.FeeRate;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @description:  前端传入的费率基本都是百分比格式的不是小数
 * @author: huanmin
 * @create: 2025-04-23 16:21
 **/
public class FeeRateLegalValidator implements ConstraintValidator<FeeRateLegal, FeeRate> {
    private double max;
    private double min;

    @Override
    public void initialize(FeeRateLegal constraintAnnotation) {
        this.max = constraintAnnotation.max();
        this.min = constraintAnnotation.min();
    }

    @Override
    public boolean isValid(FeeRate value, ConstraintValidatorContext context) {
        if (value == null) {
            return true;
        }
        //不能小于最小值
        if (value.intValue() < min) {
            return false;
        }
        //不能大于最大值
        return !(value.intValue() > max);
    }
}
